#include <QtGui>

#include "icon_label.h"
#include "invader_label.h"

IconLabel::IconLabel (const QString &iconFile, const QString &label,
                      int value, QWidget *parent)
  : QFrame (parent),
    _icon (QPixmap (iconFile))
{
  _layout = new QHBoxLayout;
  _layout->setSizeConstraint (QLayout::SetFixedSize);

  InvaderLabel *il = new InvaderLabel (label, this);
  _layout->addWidget (il);
  setValue (value);

  setLayout (_layout);
}

void IconLabel::setValue (int value)
{
  QLayoutItem *child;

  while ((child = _layout->takeAt (1)) != 0) {
    child->widget ()->deleteLater ();
    delete child;
  }

  for (int i = 0; i < value; ++i) {
    QLabel *l = new QLabel (this);
    l->setPixmap (_icon);

    _layout->addWidget (l);
  }
}
